package org.hxyjs.service.impl;


import org.hxyjs.dao.PrizetypeDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Prizetype;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.PrizetypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("PrizetypeService")
public class PrizetypeServiceImpl implements PrizetypeService {
    @Resource
    PrizetypeDao prizetypeDao;
    @Override
    public DTO<Prizetype> getAllPrizetypes()  throws Exception{
        List<Prizetype> prizetypes = prizetypeDao.getAllPrizetypes();
        MessageEnum messageEnum  = Optional.ofNullable(prizetypes).isPresent()?MessageEnum.GETPRIZETYPESUCCESS: MessageEnum.GETPRIZETYPEFAIL;
        return new DTO<Prizetype>(messageEnum.getCode(),messageEnum.getMessage(),prizetypes);
    }

    @Override
    public DTO<Prizetype> deletePrizetypeByPrino(String prino)  throws Exception{
        Integer result = prizetypeDao.deletePrizetypeByPrino(prino);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETEPRIZETYPESUCCESS:MessageEnum.DELETEPRIZETYPEFAIL;
        return new DTO<Prizetype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Prizetype> updatePrizetypeByPrino(Prizetype prizetype)  throws Exception{
        Integer result = prizetypeDao.updatePrizetypeByPrino(prizetype);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATEPRIZETYPESUCCESS:MessageEnum.UPDATEPRIZETYPEFAIL;
        return new DTO<Prizetype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Prizetype> addPrizetype(Prizetype prizetype) throws Exception {
        Integer result = prizetypeDao.addPrizetype(prizetype);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDPRIZETYPESUCCESS:MessageEnum.ADDPRIZETYPEFAIL;
        return new DTO<Prizetype>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Prizetype> getPrizetypeByPage(PageInfo pageInfo) throws Exception{
        List<Prizetype> prizetypes = prizetypeDao.getPrizetypeByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(prizetypes).isPresent()?MessageEnum.GETPRIZETYPESUCCESS: MessageEnum.GETPRIZETYPEFAIL;
        return new DTO<Prizetype>(messageEnum.getCode(),messageEnum.getMessage(),prizetypes,pageInfo);
    }
}
